<?php

include_once 'init.php';
$error = false;

if (isset ( $_POST ['login'] ) && isset ( $_POST ['password'] )) {
	
	$user = new User ( );
	$user->setLogin ( $_POST ['login'] );
	$user->setPassword ( $_POST ['password'] );
	$user->setName ( $_POST ['name'] );
	
	if (UserUtils::add ( $user )) {
		session_start ();
		$_SESSION ['curUser'] = $user;
		header ( "Location: bookmarks.php" );
	}else{
		$error = true;
	}
}

?>


<?php
require 'header';

if($error){
	echo "Bład podczas dodawania użytkownika.";	
}
?>

<script type="text/javascript">

	function testForm(){
			var form = jQuery("#regForm");
			form.find(".error").remove();
			var login = emptyValid(form.find("input[name='login']"));
			var pass  = emptyValid(form.find("input[name='password']"));
			var name = emptyValid(form.find("input[name='name']"));
			return login && pass && name;
	}

</script>

<div class="main_page">
		<div class="header"></div>
			<div class="content_b">
				<div class ="content_i">
						<b>Dołącz do nas!</b><br/><br/> 
						Wypełni formularz:<br/>
						<div style="position: absolute; top: 108px; left: 108px;">
						
						<form method="post" action="register.php" id="regForm">
							<div style="font-size: 16; font-weight: bold;">Login:
							<input type="text" name="login" 	value="<?php echo ParamUtils::getString("login"); ?>" /> <br /> 
							</div><br/> 
							<div style="font-size: 16; font-weight: bold;">Haslo:
							<input type="password" name="password" 	value="<?php echo ParamUtils::getString("password");?>" /> <br />
							</div><br/> 
							<div style="font-size: 16; font-weight: bold;">Imie: 
							<input type="text"	name="name" value="<?php echo ParamUtils::getString("name");?>" /> <br />
							</div><br/>
							<input type="submit" value="Zarejestruj" onclick="return testForm();"/>
						</form>
						</div>
				</div>
		


<?php
require 'footer';
?>
